<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/10/17
 * Time: 18:50
 * 预购商城
 */

require_once('env.php');
require_once('functions.php');

$index_obj = getSysConfig();
//$product = array("remaining_time" => "2016-10-30 23:00:00", "products_id" => 1, "products_desc_images" => "http://www.ygqq.com/static/zt/red/images/c1.png", "products_img" => "http://www.ygqq.com/static/zt/red/images/c1.png", "products_name" => "玛莎拉蒂-Ghibli 2014款 3.0T 标准版", "products_price" => "1239", "products_currency" => "NT", "products_special_price" => "999", "products_sales_num" => 2132);

$product = getDefProduct();

$date_remain = date("Y/m/d H:i:s", strtotime($product['remaining_time']));
?>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title><?php echo $index_obj['title']; ?></title>
    <meta name="keywords" content="<?php echo $index_obj['kewords']; ?>">
    <meta name="description" content="<?php echo $index_obj['description']; ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta content="" property="og:description">
    <link href="style/css/reset.css" rel="stylesheet" type="text/css"/>
    <link href="style/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="style/css/style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="header">
    <img src="<?php echo $product['products_img'] ?>">
</div>

<div class="main">
    <div class="left haveday">
        <h4 class="main-left col-xs-12"><?php echo $product['products_name'] ?></h4>
        <span id="divdown" class="main-right col-xs-12 time">僅剩 : 0 天 0 小时 0 分 0 秒 </span>
    </div>
    <div class="right">
        <h4><b><?php echo $product['products_currency'] ?><?php echo $product['products_special_price'] ?></b>
            <span><?php echo $product['products_currency'] ?><?php echo $product['products_price'] ?></span></h4>
    </div>
</div>
<div class="menu col-xs-12">
    <div class="m-left col-md-6 col-xs-12">
        <h1><img src="style/img/support1.png" alt=""/><span>支持隨時退款</span></h1>
    </div>
    <div class="m-right col-md-6 col-xs-12">
        <h1><img src="style/img/support1.png" alt=""/><span>支持貨到付款</span></h1>
    </div>
    <div class="m-bottom col-xs-12">
        <h1><img src="style/img/user1.png" alt=""/><span>已售 <?php echo $product['products_sales_num'] ?></span></h1>
    </div>
</div>
<div class="content col-xs-12">
    <h1>商品詳情</h1>
    <?php if ($product['products_desc_images']) {
        $img_array = explode("||", $product['products_desc_images']);
        foreach ($img_array as $img) {
            ?>
            <img src="<?php echo $img ?>" alt=""/>
        <?php }
    } ?>
</div>
<div id="gobuy" class="footer">
    <h1>立即搶購</h1>
</div>

<div id="buy" class="buy col-xs-12" style="padding: 0;">
    <div class="buy-head">
        <h1>提交訂單</h1>
        <img id="back" class="back" src="style/img/back1.png" alt=""/>
    </div>
    <div class="buy-name">
        <h2><b><?php echo $product['products_name'] ?></b></h2>
    </div>
    <div class="write col-xs-12">
        <h3 class="wnum col-xs-12">
            <span class="wnuma col-xs-12"><b>数&nbsp;&nbsp;&nbsp;量：</b></span>
                <span class="wnumb col-xs-12">

                    <span class="col-xs-2" style="padding: 0">
                    <!-- <input id="min" class="btn btn-primary" name="number" type="button" value="-"/>  -->
                    <img id="min" src="style/img/min2.png" style="border: 2px solid #bfbfbf; border-radius: 50%;">
                    </span>

                    <span class="col-xs-8" style="padding: 0">
                    <input id="text_box" class="col-xs-12 form-control" name="number" type="text" value="1"/>
                     </span>

                    <span class="col-xs-2" style="padding: 0; text-align: right;">
                    <!-- <input id="add" class="btn btn-primary" name="number" type="button" value="+"/> -->
                    <img id="add" src="style/img/add.png" style="border: 2px solid #FE9807; border-radius: 50%;">
                    </span>

                </span>
        </h3>

        <h3 class="wuser col-xs-12">
            <span class="wusera col-xs-12"><b>用戶名：</b></span>
            <span class="wuserb col-xs-12"><input class="input col-xs-12 form-control" type="text" id="user_name"
                                                  name="user_name" maxlength="20" placeholder="請輸入用戶名" required></span>
        </h3>

        <h3 class="wtel col-xs-12">
            <span class="tela col-xs-12"><b>手機號：</b></span>
            <span class="telb col-xs-12"><input class="input col-xs-12 form-control" type="text" id="phone" name="phone"
                                                maxlength="20" placeholder="請輸入電話" required></span>
        </h3>

        <h3 class="wem col-xs-12">
            <span class="wema col-xs-12"><b>郵&nbsp;&nbsp;&nbsp;箱：</b></span>
            <span class="wemb col-xs-12"><input class="input col-xs-12 form-control" type="text" id="email" name="email"
                                                maxlength="30" placeholder="請輸入郵箱" required></span>
        </h3>

        <div id="city">
            <div>
                <h3 class="col-xs-12">
                    <span class="col-xs-12 wadda" style="padding:0"><b>地&nbsp;&nbsp;&nbsp;址：</b></span>
                    <span class="col-xs-6 waddb"><select class="prov col-xs-12 form-control"
                                                         id="prov_id"></select></span>
                    <span class="col-xs-6 waddc"><select class="city col-xs-12 form-control" id="city_id"
                                                         disabled="disabled"></select></span>
                </h3>

                <h3 class="col-xs-12">
                    <span class="col-xs-12 waddd">
                    <input class="input addr col-xs-12 form-control" type="text" id="address" name="address"
                           maxlength="20" placeholder="詳細地址具體到街道門牌號" required>
                    </span>
                </h3>
            </div>
        </div>
    </div>
    <div>
        <span class="col-xs-2"></span>
        <span id="get" class="button get col-xs-8" onclick="doSubmit()">提交</span>
        <span class="col-xs-2"></span>
    </div>
</div>

<div id="buy-done" class="buy-done">
    <img style="padding-bottom: 10px" src="style/img/support.png">
    <br/>
    <span>提交成功</span>
</div>

<!--<div id="buy-done" class="buy-done">-->
<!--    <img style="padding-bottom: 10px" src="style/img/support.png">-->
<!--    <br/>-->
<!--    <span>提交成功</span>-->
<!--</div>-->

</body>
<script src="style/js/jquery-3.1.1.min.js"></script>
<script src="style/js/bootstrap.min.js"></script>
<script id="script_id" src="style/js/script.js" data="<?php echo WEB_ROOT; ?>"></script>
<script src="style/js/jquery.cityselect.js"></script>
<script src="//cdn.bootcss.com/jquery.nicescroll/3.6.8/jquery.nicescroll.min.js"></script>


<script type="text/javascript">
    var interval = 1000;
    function ShowCountDown(endtimestr, divname) {
        if (!endtimestr) {
            document.getElementById(divname).innerHTML = "已結束";
            $("#gobuy").unbind("click");
            $("#gobuy").css ('background-color', '#D3D3D3');
            return;
        }

        var now = new Date();
        var endDate = new Date(endtimestr);
        if (endDate.getTime() < now.getTime()) {
            document.getElementById(divname).innerHTML = "已結束";
            $("#gobuy").unbind("click");
            $("#gobuy").css ('background-color', '#D3D3D3');
            return;
        }


        var leftTime = endDate.getTime() - now.getTime();
        var leftsecond = parseInt(leftTime / 1000);
        var day1 = parseInt(leftsecond / (60 * 60 * 24));
        var hour = Math.floor((leftsecond - day1 * 24 * 60 * 60) / 3600);
        var minute = Math.floor((leftsecond - day1 * 24 * 60 * 60 - hour * 3600) / 60);
        var second = Math.floor(leftsecond - day1 * 24 * 60 * 60 - hour * 3600 - minute * 60);
        var cc = document.getElementById(divname);
        cc.innerHTML = "僅剩 : " + parseInt(day1) + " 天 " + parseInt(hour) + " 小时 " + parseInt(minute) + " 分 " + parseInt(second) + " 秒 ";
    }
    window.setInterval(function () {
        ShowCountDown("<?php echo $date_remain?>", 'divdown');//在ios系統中對日期的解析格式是xxxx/xx/xx 其餘的解析不了 就會報invalidate date
    }, interval);


    //    function lxfEndtime() {
    //        $(".lxftime").each(function () {
    //            var date = $(this).attr("endtime");
    //            if (!date) {
    //                $(this).html("已結束");
    //                $("#gobuy").unbind("click");
    //                $("#gobuy").css ('background-color', '#D3D3D3');
    //                return;
    //            }
    //            var endtime = new Date($(this).attr("endtime")).getTime();
    //            //取结束日期(毫秒值)
    //            var nowtime = new Date().getTime();
    //            //今天的日期(毫秒值)
    //            var youtime = endtime - nowtime;//还有多久(毫秒值)
    //            var seconds = youtime / 1000;
    //            var minutes = Math.floor(seconds / 60);
    //            var hours = Math.floor(minutes / 60);
    //            var days = Math.floor(hours / 24);
    //            var CDay = days;
    //            var CHour = hours % 24;
    //            var CMinute = minutes % 60;
    //            var CSecond = Math.floor(seconds % 60);
    //            //"%"是取余运算，可以理解为60进一后取余数，然后只要余数。
    //            if (endtime <= nowtime) {
    //                $(this).html("已過期")
    //                //如果结束日期小于当前日期就提示过期啦
    //            } else {
    //                $(this).html("<i>僅剩：</i><span>" + days + "</span><em> 天 </em><span>" + CHour + "</span><em> 時 </em><span>" + CMinute + "</span><em> 分 </em><span>" + CSecond + "</span><em> 秒 </em>");
    //                //输出有天数的数据
    //            }
    //        });
    //        setTimeout("lxfEndtime()", 1000);
    //    }

    //    $(function () {
    //        lxfEndtime();
    //    });


    function doSubmit() {

        var un = $("#user_name").val();
        var phone = $("#phone").val();
        var email = $("#email").val();
        var prov = $("#prov_id").val();
        var city = $("#city_id").val();
        var addr = $("#address").val();
        var num = $("#text_box").val();

        if (!un || !phone || !email || !prov || !city || !addr) {
            return;
        }
        $.ajax({
            url: 'submit_action.php',// 跳转到 action
            data: {
                user_name: un,
                phone: phone,
                email: email,
                addr: prov + city + addr,
                num: num,
                product_id: "<?php echo $product['products_id']?>",
                product_name: "<?php echo $product['products_name']?>"
            },
            type: 'post',
            cache: false,
            dataType: 'json',
            success: function (data) {
                if (data.code == "0") {
                    alert(data.msg);
                    window.location.reload();
                } else {
                    alert(data.msg);
                }
            },
            error: function () {
                alert("服務器錯誤！");
            }
        });
    }
</script>
</html>


